2085. Count Common Words With One Occurrence - LeetCode Solution


Hash Table

Python Code:

class Solution:
    def countWords(self, word1: List[str], word2: List[str]) -> int:
        dict = {}
        dict2 = {}
        for i in word1:
            if i in dict:
                dict[i] +=1
            else:
                dict[i] = 1
        for i in word2:
            if i in dict2:
                dict2[i] +=1
            else:
                dict2[i] = 1
        count = 0
        for i in dict:
            if dict[i] == 1:
                if i in dict2:
                    if dict2[i] == 1:
                        count+=1
        return count
                
        


Comments

Submit
0 Comments
More Questions

Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people